package com.xcf.controller.business.finance;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xcf.controller.base.BaseController;
import com.xcf.service.business.finance.TellerManageService;
import com.xcf.util.PageData;
import com.xcf.util.ResponseResult;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping(value="/tellerManage")
public class TellerManageController extends BaseController{
	@Resource
	private TellerManageService tellerManageService;
	/**
	 * 收付日报列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/paymentDayPaper")
	public ModelAndView paymentDayPaperList()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/finance/tellerManage/payment_daypaper_list");
		return view;
		
	}
	/**
	 * 收款数据查询
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping("/findPaymentDayPaperInfo")
	@ResponseBody
	public ResponseResult<Object> findPaymentDayPaperInfo(int page ,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData> list = tellerManageService.findPaymentDayPaperInfo(pd);
		List<PageData> list1 = new ArrayList<>();
		for(PageData p : list){
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 p.put("RECEIVABLES_BANK", p.getString("RECEIVABLES_BANK"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
//			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("SALES_ID", p.get("SALES_ID"));
			 p.put("SALES_PERSONL", p.getString("SALES_PERSONL"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("PAYMENT_NUM", p.getString("PAYMENT_NUM"));
			 p.put("MAKE_NUM", p.get("MAKE_NUM"));
	            list1.add(p);
		}
		/*response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root"+"\""+":"+json.toString()+"}");				
		response.getWriter().flush();*/
		return ResponseResult.success(new PageInfo(list));
	}

	
	/**
	 * 付款数据查询
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping("/findpaymentMoneyPaperInfo")
	@ResponseBody
	public ResponseResult<Object> findpaymentMoneyPaperInfo(int page,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData> list = tellerManageService.findpaymentMoneyInfo(pd);		
		List<PageData> list1 = new ArrayList<>();
		for(PageData p : list){
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
//			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("PAYMENT_NUM", p.getString("PAYMENT_NUM"));
			 p.put("MAKE_NUM", p.get("MAKE_NUM"));
			 list1.add(p);
		}
	/*	response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root1"+"\""+":"+json.toString()+"}");				
		response.getWriter().flush();*/
		return ResponseResult.success(new PageInfo(list));
	}
	/**
	 * 收款数据查询
	 * @throws Exception
	 */
	@RequestMapping("/findPaymentDayPaper")
	@ResponseBody
	public Object findPaymentDayPaper(int page,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData> list = tellerManageService.findPaymentDayPaperByState(pd);
		List<PageData> list1 = new ArrayList<>();
		for(PageData p : list){
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 p.put("RECEIVABLES_BANK", p.getString("RECEIVABLES_BANK"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
//			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("SALES_ID", p.get("SALES_ID"));
			 p.put("SALES_PERSONL", p.getString("SALES_PERSONL"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("PAYMENT_NUM", p.getString("PAYMENT_NUM"));
			 p.put("MAKE_NUM", p.get("MAKE_NUM"));
	            list1.add(p);
		}
		/*response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root"+"\""+":"+json.toString()+"}");				
		response.getWriter().flush();*/
		return ResponseResult.success(new PageInfo(list));
	}

	
	/**
	 * 付款数据查询
	 * @throws Exception
	 */
	@RequestMapping("/findpaymentMoneyPaper")
	@ResponseBody
	public Object findpaymentMoneyPaper(int page,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData> list = tellerManageService.findpaymentMoneyByState(pd);
		List<PageData>list1 = new ArrayList<>();
		for(PageData p : list){
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
//			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("PAYMENT_NUM", p.getString("PAYMENT_NUM"));
			 p.put("MAKE_NUM", p.get("MAKE_NUM"));
	            list1.add(p);
		}
/*		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root1"+"\""+":"+json.toString()+"}");				
		response.getWriter().flush();*/
		return ResponseResult.success(new PageInfo(list));
	}
	/**
	 * 收付款列表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/paymentMoney")
	public ModelAndView paymentMoneyList()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/finance/tellerManage/payment_money_list");
		return view;
		
	}
	/**
	 * 收付款明细
	 * @throws Exception
	 */
	@RequestMapping("/findPaymentMoneyDetailInfo")
	@ResponseBody
	public Object findPaymentMoneyDetailInfo(int page,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData> list = tellerManageService.findPaymentMoneyDetall(pd);
//		List<PageData> list1 = new ArrayList<>();
//		for(PageData p : list){
//			
//			 p.put("ID", p.get("ID"));
//			 p.put("UIIT", p.getString("UIIT"));
//			 p.put("CURRENCY", p.getString("CURRENCY"));
//			 p.put("AMOUNT", p.getString("AMOUNT"));
//			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
//			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
//			 p.put("SALES_ID", p.get("SALES_ID"));
//			 p.put("SALES_PERSONL", p.getString("SALES_PERSONL"));
//			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
//			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
//			 p.put("PAYMENT_NUM", p.getString("PAYMENT_NUM"));
//			 p.put("MAKE_NUM", p.get("MAKE_NUM"));
//			 p.put("PAYMENT_APPLY", p.get("PAYMENT_APPLY"));
//			 p.put("ACCOUNT_VERIFICATION", p.get("ACCOUNT_VERIFICATION"));
//			 p.put("RECEIVABLES_CONFIRM", p.get("RECEIVABLES_CONFIRM"));
//			 
//	            list1.add(p);
//		}
		return ResponseResult.success(new PageInfo(list));
	}
	/**
	 * 收付款信息
	 * @throws Exception
	 */
	@RequestMapping("/findPaymentMoneyInfo")
	@ResponseBody
	public Object findPaymentMoneyInfo(int page,int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);	
		//查询收付预报和收付日报的信息
		List<PageData> list = tellerManageService.findPaymentDayPaperByState(pd);
		List<PageData> list1 = new ArrayList<>();
		for(PageData p : list){
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("RECEIVABLES_NUM", p.getString("RECEIVABLES_NUM"));
			 p.put("MAKE_NUM", p.getString("MAKE_NUM"));

	            list1.add(p);
		}
		return ResponseResult.success(new PageInfo(list));
	}
	/**
	 * 收付款信息
	 * @throws Exception
	 */
	@RequestMapping("/findPayMoneyInfo")
	@ResponseBody
	public Object findPayMoneyInfo(int page, int limit)throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		PageHelper.startPage(page, limit);
		//查询收付预报和收付日报的信息
		List<PageData> list = tellerManageService.findpaymentMoneyByState(pd);
		List<PageData> list1 = new ArrayList<>();
		for(PageData p : list){			
			 p.put("ID", p.get("ID"));
			 p.put("UIIT", p.getString("UIIT"));
			 p.put("CURRENCY", p.getString("CURRENCY"));
			 p.put("AMOUNT", p.getString("AMOUNT"));
			 if(p.get("RECEIVABLES_TIME")!=null || p.get("RECEIVABLES_TIME")!=""){
				 	
			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			        String RECEIVABLES_TIME = sdf.format(p.get("RECEIVABLES_TIME"));
				 p.put("RECEIVABLES_TIME", RECEIVABLES_TIME);
			 }
			 p.put("DEPARTMENT_ID", p.get("DEPARTMENT_ID"));
			 p.put("DEPARTMENT", p.getString("DEPARTMENT"));
			 p.put("BUSINESS_TYPE_ID", p.get("BUSINESS_TYPE_ID"));
			 p.put("BUSINESS_TYPE", p.getString("BUSINESS_TYPE"));
			 p.put("RECEIVABLES_NUM", p.getString("RECEIVABLES_NUM"));
			 p.put("MAKE_NUM", p.getString("MAKE_NUM"));

	            list1.add(p);
		}
		return ResponseResult.success(new PageInfo(list));
	}
	/**
	 * 修改状态
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editConfirm")
	@ResponseBody
	public String editConfirm()throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		String data = pd.getString("array");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("id").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			pdq.put("IS_CONFIRM", pd.get("state"));
			tellerManageService.eidtConfirm(pdq);
		}
		return null;
		
	}
	/**
	 * 修改状态
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editPayMoneyConfirm")
	@ResponseBody
	public String editPayMoneyConfirm()throws Exception{
		PageData pd = new PageData();
		pd= this.getPageData();
		String data = pd.getString("array");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("id").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			pdq.put("IS_CONFIRM", pd.get("state"));
			tellerManageService.editPayMoney(pdq);
		}
		return null;
		
	}
}
